package com.demo.common;

import lombok.Builder;
import lombok.Getter;
import lombok.Setter;
import java.util.HashMap;
import java.util.Map;

@Getter
@Setter
@Builder
public class ErrorDetail {
    private int httpCode;    // HTTP状态码
    private String message;  // 用户友好消息
    private String domain;   // 错误领域
    private String reason;   // 技术原因

    @Builder.Default
    private Map<String, Object> metadata = new HashMap<>();

    public static ErrorDetail fromHttpError(HttpErrorType errorType) {
        return ErrorDetail.builder()
                .httpCode(errorType.getStatusCode())
                .message(errorType.getDescription())
                .build();
    }
    // 手动添加的方法
    public ErrorDetail addMetadata(String key, Object value) {
        this.metadata.put(key, value);
        return this;
    }
}